<title>Cornice PHP Framework >> Setup</title>
<?php
error_reporting(E_ALL);
ini_set("display_errors","On");

//open dir
$dir = opendir("modules");
if ($dir===false) 
  exit;

//get module list
$modules = array();
while (($file=readdir($dir))!==false) {
  $info = pathinfo($file);
  if (strtolower($info["extension"])!=="xml")
    continue;
  array_push($modules,strtolower($info["filename"]));
}
closedir($dir);

//get path to current dir
$script_name = $_SERVER["SCRIPT_NAME"];
$last_slash  = strrpos($script_name,"/");
if ($last_slash===0)
  $path = "/";
else
  $path = substr($script_name,0,$last_slash);

//heading text for htaccess
$heading = <<<HEADING
#=============================================================================
# Cornice PHP Framework & Website Builder
# Freeware (f) 2011 by Inforo Software & Computer
#=============================================================================

Options +FollowSymlinks
RewriteEngine on\r\n\r\n
HEADING;

//rewrite text
$rewrite = <<<REWRITE
RewriteRule ^##module##$ ##path##/index.php?##module## 
RewriteRule ^##module##/(.*)$ ##path##/index.php?##module##/$1 
RewriteRule ^##module##_(.*)$ ##path##/index.php?##module##_$1 
REWRITE;

//generate htaccess text
$text = $heading;
foreach ($modules as $module) {
  $temp = $rewrite;
  $temp = str_replace("##module##",$module,$temp);
  $temp = str_replace("##path##",$path,$temp);
  $text .= "$temp\r\n\r\n";
}

//save to file
file_put_contents(".htaccess",$text);
?>

<!--CSS---------------------------------------------------------------------->
<style>
body {
  margin:0; padding:20px; padding-bottom:100px; background:skyblue;
  font-family:georgia; font-size:12px; font-weight:normal; line-height:20px;
}
.div_setup {
  border:gold 1px solid; background:white; width:900px; margin-left:auto;
  margin-right:auto;
}
.div_setup_inner {
  margin:10px;
}
.div_notes {
  border-bottom:#gold 1px solid;
}
</style>

<!--HTML--------------------------------------------------------------------->
<div class="div_setup">
<div class="div_setup_inner">

<div class="div_notes">
<b>Cornice PHP Framework & Website Builder</b><br>
Freware (f) 2011 by Inforo Software & Computer<br>
</div>
<div>&nbsp;</div>

<div class="div_notes">
<b>Basic setup</b>
</div>
<div>&nbsp;</div>

Operations done: configuration of root htaccess file<br>
Available modules: <?php
foreach ($modules as $module) { ?>
  <a target="_blank" href="<?php echo $module; ?>"><?php
  echo $module; ?></a> <?php
} ?>
<div>&nbsp;</div>

<div class="div_notes">
<b>Notes</b>:
</div>
<div>&nbsp;</div>

(1) Module 'devtools' is not accessible from network computer.
<div>&nbsp;</div>

(2) Default authentication for 'backend' is (admin/123456).
<div>&nbsp;</div>

(3) To reset the default authentication for backend manually, delete the file
'passwords.php' in 'data/secured' directory; and open module 
<a target="_blank" href="devtools">devtools</a>, 
then go to Menu >> Data >> 
<a target="_blank" href="devtools_passwords">Passwords</a>; the default
authentication for 'backend' module will be restored.

</div>
</div>